<?php

$request = $this->input->raw_input_stream;

$info=json_decode($request,true);

if($this->goods_model->getbytbid($info["id"],$shop["id"])) die("exist");

$product=array(
    "catid"=>$shop["id"],
    "tbid"=>$info["id"],
    "name"=>$info["name"],
    "thumb"=>serialize($info["img"]),
    "source"=>"yahoo.jp",
    "source_url"=>$info["url"],
    "price"=>$info["price"],
    "sales"=>$info["gsales"],
    "desc"=>$info["desc"]
);

$extra=["cate"=>$info["cate"]];
$product["meta"]=json_encode($extra,JSON_UNESCAPED_UNICODE);

$prop=array();


if($info['title1']&&$info["color"])
{
    $prop["vv"][]=["name"=>$info['title1'],"value"=>$info["color"]];
}
if($info['title2']&&$info["size"])
{
    $prop["vv"][]=["name"=>$info['title2'],"value"=>$info["size"]];
}

$product["option"]=serialize($prop);

if($this->goods_model->create($product)){
    die("ok");
}else{
    die("error");
}